package com.example.stujava.module.annotation;

import java.lang.reflect.Method;

public class AnnotationTest {
    public static void main(String[] args) {
        //获取类注解
        Class<Father> fatherClass = Father.class;
        boolean isAnnotationPresent = fatherClass.isAnnotationPresent(Person.class);
        if (isAnnotationPresent) {
            Person annotation = fatherClass.getAnnotation(Person.class);
            System.out.println(annotation.name());
            System.out.println(annotation.age());
        }

        Father father = new Father();
        father.getPerson();
    }




    @Person(name  ="xi",age = 50)
    static
    class Father {
        @Person(name = "xiaohong",age = 18)
        public   void getPerson() {
            try {
                Method getPerson = Father.class.getDeclaredMethod("getPerson");
                boolean annotationPresent = getPerson.isAnnotationPresent(Person.class);
                if (annotationPresent) {
                    Person person = getPerson.getAnnotation(Person.class);
                    String name = person.name();
                    System.out.println(name);
                }
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
        }
    }
}


//    /**是否存在对应 Annotation 对象*/
//    public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
//        return GenericDeclaration.super.isAnnotationPresent(annotationClass);
//    }
//
//    /**获取 Annotation 对象*/
//    public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
//        Objects.requireNonNull(annotationClass);
//
//        return (A) annotationData().annotations.get(annotationClass);
//    }
//    /**获取所有 Annotation 对象数组*/
//    public Annotation[] getAnnotations() {
//        return AnnotationParser.toArray(annotationData().annotations);
//    }